﻿using System.Collections.Generic;

namespace SAM.Framework.Repository.Repositories.Pager
{
    /// <summary>
    /// 分页的配置信息
    /// </summary>
    public class PageOption<TEntity>
    {
        /// <summary>
        /// 页索引号
        /// </summary>
        public int PageIndex { get; set; }

        /// <summary>
        /// 页大小
        /// </summary>
        public int PageSize { get; set; }

        /// <summary>
        /// 查询条件
        /// </summary>
        public dynamic Predicate { get; set; }

        /// <summary>
        /// 排序字段列表
        /// </summary>
        public IList<SortInfo> SortInfos { get; set; }

        public PageOption(int pageIndex, int pageSize)
        {
            this.PageIndex = pageIndex;
            this.PageSize = pageSize;
            this.SortInfos = new List<SortInfo>();
        } 
        /// <summary>
        /// 添加排序字段
        /// </summary>
        /// <param name="expression"></param>
        /// <param name="sortType"></param>
        public void AddSort(string fieldName, SortType sortType)
        {
            this.SortInfos.Add(new SortInfo(fieldName, sortType));
        }
    }
}
